package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.pojos.AutoDto;
import com.heima.model.user.pojos.UserRealname;
import com.itheima.mapping.UserAutomapper;
import com.itheima.service.UserAutoService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAutoServiceImpl extends ServiceImpl<UserAutomapper,UserRealname> implements UserAutoService {
    @Override
    public ResponseResult list(AutoDto dto) {
        IPage<UserRealname> page=new Page<>(dto.getPage(), dto.getSize());
        LambdaQueryWrapper<UserRealname> wrapper=new LambdaQueryWrapper<>();
        wrapper.orderByDesc(UserRealname ::getCreatedTime);
       // wrapper.eq(UserRealname::getStatus,dto.getStatus());
        List<UserRealname> list = list(wrapper);
        page=page(page,wrapper);
      ResponseResult result=  new PageResponseResult(dto.getPage(), dto.getSize(), (int) page.getTotal());
      result.setData(page.getRecords());
      return result.ok(list);
    }

    @Override
    public ResponseResult authFail(AutoDto dto) {
        LambdaQueryWrapper<UserRealname> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserRealname ::getId,dto.getId());
        UserRealname userRealname = getOne(wrapper);

        userRealname.setStatus((short) 2);

        updateById(userRealname);
        ResponseResult result = new ResponseResult();
        result.setData(userRealname);
        return result;
    }

    @Override
    public ResponseResult authPass(AutoDto dto) {
        LambdaQueryWrapper<UserRealname> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserRealname ::getId,dto.getId());
        UserRealname userRealname = getOne(wrapper);
        userRealname.setStatus((short) 9);
        updateById(userRealname);
        ResponseResult result = new ResponseResult();
        result.setData(userRealname);
        return result;
    }
}
